package com.liuyi.netty.im.test.config.thread;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * 异步线程池配置
 */
@ConfigurationProperties(
        prefix = "rapid.thread.async"
)
@Component
@Data
public class ThreadAsyncProperties {

    /**
     * 核心数
     * 如果是CPU密集型应用，则线程池大小设置为N+1
     * 如果是IO密集型应用，则线程池大小设置为2N+1
     */
    private int corePoolSize = 9;
    /**
     * 最大线程数
     */
    private int maxPoolSize = 30;
    /**
     * 允许线程的空闲时间60秒：当超过了核心线程之外的线程在空闲时间到达之后会被销毁
     */
    private int keepAliveSeconds = 60;
    /**
     * 缓冲队列
     */
    private int queueCapacity = 1000;
    /**
     * 等待任务在关机时完成--表明等待所有线程执行完
     */
    private boolean waitForTasksToCompleteOnShutdown = false;
    /**
     * 等待时间 （默认为0，此时立即停止），并没等待xx秒后强制停止
     */
    private int awaitTerminationMillis = 0;
    /**
     * 线程池名称前辍
     */
    private String namePrefix = "rapid-develop-";

    private Class<? extends RejectedExecutionHandler> rejectedExecutionHandler = ThreadPoolExecutor.AbortPolicy.class;
}
